import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Input, Picker, Image, Form, Button } from "@tarojs/components-rn";
import { AtImagePicker } from 'taro-ui';
import { inject, observer } from "@tarojs/mobx-rn";
import PageFooterInfo from "../../components/PageFooterInfo";
import { getRuntime, educationArr, workYearsArr } from "../../utils/common";
import architectStyleSheet from "./architect_styles";
import right from '../../assets/img/right.png';
var _styleSheet = architectStyleSheet;
let Page1 = class Page1 extends Component {
  constructor(props) {
    super(props);
    this.state = {
      registrationType: 2,
      certificateArr: ['一级建造师', '二级建造师'],
      certificate: '',
      highestEducatioArr: educationArr,
      highestEducatio: '',
      major: '',
      yearsOfWorkingArr: workYearsArr,
      yearsOfWorking: '',
      placeOfWork: '',
      unitAddress: '',
      contactName: '',
      contactPhone: '',
      contactEmail: '',
      identityCardPhotoArr: [],
      identityCardPhoto: '',
      graduationCertificateArr: [],
      graduationCertificate: '',
      loading: false,
      disabled: false,
      submitText: '立即报名'
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '建企类' });
  }
  saveApplyInfoAsync(e) {
    console.log(e.detail.value);
    let { major, placeOfWork, unitAddress, contactName, contactPhone, contactEmail } = e.detail.value;
    let { yearsOfWorking, registrationType, certificate, highestEducatio, identityCardPhoto, graduationCertificate } = this.state;
    if (!certificate) {
      getRuntime().showToast('培训证书不能为空~');
      return;
    }
    if (!yearsOfWorking) {
      getRuntime().showToast('工作年限不能为空~');
      return;
    }
    if (!contactName) {
      getRuntime().showToast('联系人姓名不能为空~');
      return;
    }
    if (!contactPhone) {
      getRuntime().showToast('联系人电话不能为空~');
      return;
    }
    let businessSchool = this.props.stores.BusinessSchool;
    this.setState({
      loading: true,
      disabled: true,
      submitText: '数据提交中...'
    });
    businessSchool.saveApplyInfoAsync({
      form: {
        registrationType,
        certificate: certificate,
        highestEducatio: highestEducatio,
        major,
        yearsOfWorking,
        placeOfWork,
        unitAddress,
        identityCardPhoto: identityCardPhoto,
        graduationCertificate: graduationCertificate,
        contactName,
        contactPhone,
        contactEmail
      },
      callback: () => {
        this.setState({
          loading: false,
          disabled: false,
          submitText: '立即报名'
        });
        this.handelRouter('/pages/other/submit_success');
      }
    });
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  changeImgI(e) {
    this.setState({
      identityCardPhotoArr: e
    }, () => {
      getRuntime().uploadFile(e, res => {
        //console.log(res.join('+'))
        //console.log(JSON.stringify(res))
        this.setState({
          identityCardPhoto: res.join(',')
        });
      });
    });
  }
  changeImgG(e) {
    this.setState({
      graduationCertificateArr: e
    }, () => {
      getRuntime().uploadFile(e, res => {
        //console.log(res.join('+'))
        //console.log(JSON.stringify(res))
        this.setState({
          graduationCertificate: res.join(',')
        });
      });
    });
  }
  changePicker(type, e) {
    this.setState({
      [type]: this.state[[type] + 'Arr'][e.detail.value]
    });
  }
  render() {
    let { certificateArr, certificate, highestEducatioArr, highestEducatio, identityCardPhotoArr, graduationCertificateArr, yearsOfWorkingArr, yearsOfWorking, loading, disabled, submitText } = this.state;
    return <View style={_styleSheet["from-wrap"]}>
        <Form onSubmit={this.saveApplyInfoAsync.bind(this)}>
          <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
            <View style={_styleSheet["input-group"]}>
              <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>培训证书</View>
              <Picker mode="selector" name="certificate" range={certificateArr} onChange={this.changePicker.bind(this, 'certificate')} style={_styleSheet["input-picker"]}>
                <View style={_styleSheet["tt"]}>
                  {!certificate && <View style={[_styleSheet["from-input"], _styleSheet["picker-con"], _styleSheet["placeholder-class"]]}>请选择</View>}
                  {certificate && <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{certificate}</View>}
                  <Image src={right} style={_styleSheet["drop-down-icon"]} />
                </View>
              </Picker>
            </View>
            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>最高学历</View>
              <Picker mode="selector" range={highestEducatioArr} onChange={this.changePicker.bind(this, 'highestEducatio')} style={_styleSheet["input-picker"]}>
                <View style={_styleSheet["tt"]}>
                  {!highestEducatio && <View style={[_styleSheet["from-input"], _styleSheet["picker-con"], _styleSheet["placeholder-class"]]}>请选择</View>}
                  {highestEducatio && <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{highestEducatio}</View>}
                  <Image src={right} style={_styleSheet["drop-down-icon"]} />
                </View>
              </Picker>
            </View>
            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>所学专业</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写所学专业" name="major" style={_styleSheet["from-input"]} />
            </View>
            <View style={_styleSheet["input-group"]}>
              <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>工作年限</View>
              
              <Picker mode="selector" range={yearsOfWorkingArr} onChange={this.changePicker.bind(this, 'yearsOfWorking')} style={_styleSheet["input-picker"]}>
                <View style={_styleSheet["tt"]}>
                  {!yearsOfWorking && <View style={[_styleSheet["from-input"], _styleSheet["picker-con"], _styleSheet["placeholder-class"]]}>请选择</View>}
                  {yearsOfWorking && <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{yearsOfWorking}年</View>}
                  <Image src={right} style={_styleSheet["drop-down-icon"]} />
                </View>
              </Picker>
            </View>
            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>工作单位</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写工作单位" name="placeOfWork" style={_styleSheet["from-input"]} />
            </View>
            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>单位地址</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写单位地址" name="unitAddress" style={_styleSheet["from-input"]} />
            </View>
            <View style={[_styleSheet["input-group"], _styleSheet["input-upload"]]}>
              <View style={_styleSheet["input-name"]}>上传法人身份证正反面</View>
              <AtImagePicker length={4} count={2} showAddBtn={true} files={identityCardPhotoArr} onChange={this.changeImgI.bind(this)} />
            </View>
            <View style={[_styleSheet["input-group"], _styleSheet["input-upload"]]}>
              <View style={_styleSheet["input-name"]}>上传毕业证和学位证</View>
              <AtImagePicker length={4} count={2} showAddBtn={true} files={graduationCertificateArr} onChange={this.changeImgG.bind(this)} />
            </View>
          </View>

          <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
            <View style={_styleSheet["input-group"]}>
              <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系人</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写联系人" name="contactName" style={_styleSheet["from-input"]} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系电话</View>
              <Input type={"number"} maxLength={11} placeholderClass="placeholder_class" placeholder="请填写联系电话" name="contactPhone" style={_styleSheet["from-input"]} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>联系邮箱</View>
              <Input placeholderClass="placeholder_class" placeholder="请填写联系邮箱" name="contactEmail" style={_styleSheet["from-input"]} />
            </View>
          </View>

          <Button formType={"submit"} loading={loading} disabled={disabled} style={_styleSheet["page-submit"]}>{submitText}</Button>
        </Form>
        <PageFooterInfo />
      </View>;
  }
};
Page1 = tslib_1.__decorate([inject("stores"), observer], Page1);
export default Page1;